<template>
  <a-modal :open="open" width="640px" :title="cancelType === 0 ? '撤销签收' : '撤销申请'" ok-text="确认撤销" centered @ok="onOk" @cancel="onCancel">
    <div class="pl-6 pr-2 pt-1 mb-2 pb-1 border-dashed border-0 border-b-2 bg-black-1">
      <div class="flex items-center justify-between">
        <template v-if="formState.advType === 0">
          <DoctorAdviceOrder
            :row-data="formState"
            :params-key="{
              mc: 'adv.mc',
              gg: 'adv.gg',
              sl: 'clinicalDose',
              dw: 'clinicalDoseUnit',
              yf: 'deliverRoute.fyff',
              pl: 'fqy.pl',
              drugPathName: 'drugPathName'
            }"
          />
        </template>
        <template v-else>
          <div class="pl-2">
            {{ formState?.advName }}
          </div>
        </template>
        <div class="text-red-600 font-bold">{{ formState?.planExecTime }}</div>
      </div>
    </div>
    <a-form :model="formState" class="form-style-flex mt-3" :label-col="{ style: { width: '100px' } }">
      <a-form-item label="批准人" class="w-1/2">
        <a-input v-model:value="formState.empId" :disabled="formState.allowCancelApplyInpAdvice" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="密码" class="w-1/2">
        <a-input v-model:value="formState.pwd" :disabled="formState.allowCancelApplyInpAdvice" type="password" placeholder="请输入" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script setup>
import { ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import { post } from '@/utils/request'

const emit = defineEmits(['update:open', 'success'])
const props = defineProps({
  open: Boolean,
  rowData: {
    type: Object,
    default: () => ({})
  },
  selectedItem: {
    type: Object,
    default: () => ({})
  },
  cancelType: {
    type: Number,
    default: 0 //0 撤销签收  1  撤销申请
  }
})
const formState = ref({
  advName: '',
  unit: '',
  amount: '',
  empId: '',
  pwd: ''
})

const onOk = async () => {
  //撤销申请
  const res = await post('/inp/clinicalOrder/doCancelApplyClinicalOrder', {
    id: formState.value.id,
    empId: formState.value.empId,
    pwd: formState.value.pwd
  })
  if (res.code !== 0) return message.error(res.msg || '操作失败')
  message.success(res.msg || '操作成功')
  emit('success')
  onCancel()
}
watch(
  () => props.open,
  (val) => {
    if (val && props.rowData?.advName) {
      formState.value = { ...props.rowData }
    } else {
      formState.value = {}
    }
  },
  {
    immediate: true
  }
)

const onCancel = () => {
  emit('update:open', false)
}
</script>
<style lang="less">
.bg-black-1 {
  background: rgba(0, 0, 0, 0.1);
}
</style>
